#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+7;
vector<int> a(maxn);
string s;
void reset() {
  a.clear();
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
  int tc; cin>>tc;
  while(tc--) {
    reset();
    int n; cin>>n; cin.get();
    int ch; int i=0;
    while((ch=cin.get())!='\n') {
      if(ch=='*') {
        a.push_back(i);
      }
      i++;
    }
    int len = a.size();
    int mid = a.size()/2;
    int pos = a[mid];
    long long res = 0;
    for(int i=mid-1; i>=0; --i) {
      pos--;
      res += pos -a[i];
    }
    pos = a[mid];
    for(int i=mid+1; i<len; ++i) {
      pos++;
      res += a[i]-pos;
    }
    cout<<res<<'\n';
  }
}
